package com.bestcem.xm.common.core.sql;

/**
 * @author ming.xue <ming.xue@idiaoyan.com>
 * @desc 动态条件编译特性
 * @date 2021-12-16
 */
public enum CompileFeature {
    /**
     * 跳过问卷条件编译
     */
    SKIP_SURVEY_CONDITION,

    /**
     * 检查扩展字段是否存在
     */
    CHECK_EXTEND_FIELD_EXISTS,

    /**
     * 检查标签是否存在
     */
    CHECK_LABEL_EXISTS,

    /**
     * 检查问卷项目是否存在
     */
    CHECK_SURVEY_EXISTS,

    /**
     * 检查标签依赖深度
     */
    CHECK_LABEL_DEPENDENCY_DEPTH
    ;

    CompileFeature(){
        mask = (1 << ordinal());
    }

    private final int mask;

    public final int getMask() {
        return mask;
    }

    public static boolean isNotEnabled(int features, CompileFeature feature) {
        return !CompileFeature.isEnabled(features, feature);
    }

    public static boolean isEnabled(int features, CompileFeature feature) {
        return (features & feature.mask) != 0;
    }

    public static int of(CompileFeature... features) {
        if (features == null) {
            return 0;
        }

        int value = 0;

        for (CompileFeature feature: features) {
            value |= feature.mask;
        }

        return value;
    }
}
